Skip to content

fix(attach): give every document its own attach-to-process sheet - #96

Merged
Mx-Iris merged 1 commit into
mainfrom
fix/attach-to-process-per-document-controller
Aug 12, 2026
Merged

fix(attach): give every document its own attach-to-process sheet#96
Mx-Iris merged 1 commit into
mainfrom
fix/attach-to-process-per-document-controller

Conversation

@Mx-Iris

@Mx-Iris Mx-Iris commented Aug 12, 2026

Copy link
Copy Markdown
Member

The bug

AttachToProcessViewController was held as a shared singleton behind @Dependency(\.attachToProcessViewController). MainCoordinator is per-document, so every open document resolved and presented the same controller instance.

Attach To Process is presented as a sheet on the document's root window (.presentOnRoot(_, mode: .asSheet)), and a view controller can only be presented from one window at a time — opening it in a second document while the first still has it up crashes the app. Even without the crash, setupBindings(for:) rebinds the shared instance to the second document's view model, so the first document's sheet would keep driving the wrong document.

The fix

Construct the controller per presentation, the way every other route in MainCoordinator does. The @DependencyEntry and the fileprivate static let shared go away with it.

What this gives up

6849d78 introduced the shared instance so the picker would remember the last-selected tab and running row across reopens. That is lost again here. That state belongs in the view model or AppDefaults, not in a controller instance shared between documents — worth a follow-up, but not at the price of a crash.

Related

v2.1.0 has been pulled from the appcast in #95; this is the fix that a 2.1.1 hotfix would carry.

The controller was a shared singleton behind
`@Dependency(\.attachToProcessViewController)`, so all open documents
presented the same instance. Attach To Process is presented as a sheet on
the document's root window, and a view controller can only be presented
from one window at a time — opening it in a second document while the
first still has it up crashes the app. `setupBindings(for:)` also rebinds
the shared instance to the second document's view model, so the first
document's sheet would keep driving the wrong document even without the
crash.

Construct the controller per presentation instead, the way every other
route in MainCoordinator does.

This gives up what 6849d78 bought: the picker no longer remembers the
last-selected tab and row across reopens. That state belongs in the view
model or AppDefaults, not in a controller instance shared between
documents.
Copilot AI lite review requested due to automatic review settings August 12, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the document-based app flow by ensuring Attach To Process is presented with a per-document AttachToProcessViewController instance, rather than a shared singleton that could be rebound/presented across multiple windows.

Changes:

  • Removed the dependency-injected singleton AttachToProcessViewController and its DependencyValues entry.
  • Updated MainCoordinator to construct a fresh AttachToProcessViewController() per .attachToProcess route presentation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
RuntimeViewerUsingAppKit/RuntimeViewerUsingAppKit/Main/MainCoordinator.swift Stops resolving a shared controller via @Dependency and instead instantiates a new sheet controller per document route.
RuntimeViewerUsingAppKit/RuntimeViewerUsingAppKit/Attach Process/AttachToProcessViewController.swift Removes the shared singleton and dependency entry that caused cross-document reuse.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@@ -8,8 +8,6 @@ import DependenciesMacros
final class AttachToProcessViewController: UXKitViewController<AttachToProcessViewModel> {
@Mx-Iris
Mx-Iris merged commit c324e78 into main Aug 12, 2026
1 check passed
@Mx-Iris
Mx-Iris deleted the fix/attach-to-process-per-document-controller branch August 12, 2026 15:51
@Mx-Iris Mx-Iris mentioned this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants